package com.wujin.provider.my.observer;

import java.util.ArrayList;
import java.util.Iterator;

/**
 * @author Wu Jin
 * @create 2018-03-28 下午 5:42
 */
public abstract class AbstractSubject implements Subject{

    private ArrayList<Observer> vector = new ArrayList<>();

    @Override
    public void add(Observer observer) {
        vector.add(observer);
    }

    @Override
    public void delete(Observer observer) {
        vector.remove(observer);
    }

    @Override
    public void notifyObservers() {

        Iterator<Observer> observers = vector.iterator();

        while(observers.hasNext()) {
            observers.next().update();
        }

    }
}
